﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace FCMS
{
    public class Encrypt
    {
        public static string ComputePasswordHash(string password)
        {
            byte[] data = MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(password));

            StringBuilder hash = new StringBuilder(32);
            for (int i = 0; i < data.Length; i++)
            {
                int hi, low;

                hi = (int)(data[i] >> 4);
                low = (int)(data[i] & (byte)0x0F);

                if (hi < 10)
                {
                    hash.Append((char)(48 + hi));
                }
                else
                {
                    hash.Append((char)(55 + hi));
                }

                if (low < 10)
                {
                    hash.Append((char)(48 + low));
                }
                else
                {
                    hash.Append((char)(55 + low));
                }
            }

            return hash.ToString();
        }
    }
}
